package com.kaibes.web.encryption;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

public class RsaKeyDeserialize extends JsonDeserializer<RsaKey> {

	@Override
	public RsaKey deserialize(JsonParser p, DeserializationContext ctxt)
			throws IOException, JsonProcessingException {
		ObjectCodec oc = p.getCodec();
        JsonNode node = oc.readTree(p);
        RsaKey obj = new RsaKey();
        obj.setPrivateKey(node.get("privateKey").asText());
        obj.setPublicKey(node.get("publicKey").asText());
		return obj;
	}

}
